﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using AAA.Meta.Quote.Data;
using AAA.DataSource;
using AAA.DesignPattern.Singleton;

namespace AAA.TradeLanguage
{
    public class LastPriceUpdate : IVariableCalculate
    {
        #region IObserver Members

        public void Update(object oSource, AAA.DesignPattern.Observer.IMessageInfo miMessage)
        {
            float fCurrentPrice = float.NaN;
            string strSymbolId = "";
            try
            {
                switch (miMessage.MessageSubject)
                {
                    case DataSourceConstants.TICK_RECEIVE:
                        fCurrentPrice = ((TickData)miMessage.Message).Price;
                        strSymbolId = ((TickData)miMessage.Message).SymbolId;
                        break;
                    case DataSourceConstants.BAR_RECEIVE:
                        fCurrentPrice = ((BarData)miMessage.Message).Close;
                        strSymbolId = ((BarData)miMessage.Message).SymbolId;
                        break;
                }
                SystemParameter.Parameter[strSymbolId] = fCurrentPrice;
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }

        #endregion
    }
}
